App.require(function () {
    var app = App.getCurrent();

    app.definePage("cSelectScene", {
        getDomObj: function () {
            this.attachDom(".btn-group", "btnGroup")
                .attachDom(".popup-scene-list", "sceneList")
                .attachEvent("sceneList", "click", this.clickSceneListHandler, false)
                .attachEvent("btnGroup", "btnclick", this.btnClickHandler, false);
        },
        clickSceneListHandler: function (ev) {
            var div = Component.getNodeName(ev.target, "DIV"), scene = null;
            if (div.dataset.id) {
                scene = {
                    name: "testScene",
                    option: {},
                    widgets: [
                        {
                            type: "column",
                            style: {
                                x: 100, y: 200, marker: "triangle", markerOffset: "0 -10", fill: "red"
                            },
                            mockData: [
                                { value: 23, stroke: "black", rstart: 4, rend: 8 },
                                { value: 18 },
                                { value: 8 },
                                { value: 35 }
                            ],
                            behaviors: [
                                { type: "active", style: {} },
                                { type: "remove", style: {} },
                                {
                                    type: "pos",
                                    style: {
                                        xmin: -10, xmax: 10, xstep: 1, ymin: -10, ymax: 10, ystep: 1
                                    }
                                },
                                {
                                    type: "percentUp",
                                    style: {
                                        from: 0, to: 1, duration: 2000
                                    }
                                }
                            ]
                        },
                        {
                            type: "image",
                            style: {
                                x: 100, y: 100, width: 50, height: 50, url: "asdfadf"
                            },
                            behaviors: [
                                { type: "active", style: {} },
                                { type: "remove", style: {} },
                                {
                                    type: "pos",
                                    style: {
                                        xmin: -10, xmax: 10, xstep: 1, ymin: -10, ymax: 10, ystep: 1
                                    }
                                }
                            ]
                        }
                    ],
                    resources: {
                        images: {
                            asdfadf: "/public/img/1.png"
                        }
                    },
                    marker: {
                        triangle: {
                            type: "path",
                            style: {
                                path: "M -10 0 10 0 0 20 Z",
                                fill: "red",
                                stroke: "gray"
                            }
                        }
                    },
                    title: "现成页",
                    url: "/public/img/1.png",
                    description: "asdfasdf"
                }
            }
            else {
                scene = {
                    name: "blank",
                    option: {},
                    widgets: [],
                    resources: {},
                    marker: {},
                    title: "空白页"
                };
            }
            app.currentPage.dispatchEvent("renderscene", {
                scene: scene,
                popup: this.parent
            }); 
        },
        btnClickHandler: function (ev) {
            this.parent.hidden();
        },
        render: function (next) {
            this.data.scenes = [{
                id: "firstid",
                title: "首屏",
                name: "index",
                url: "/public/img/1.png",
                description: "首屏默认视图"
            }];
            this.fetch("./index.html", function (text) {
                next(this.renderHTML(text));
            })
        }
    });
})